<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a="http://richfaces.org/a4j" xmlns:a4j="http://richfaces.org/a4j"
	template="/layout/template_box.xhtml">

	<ui:define name="head">

		<script type="text/javascript">
		function isDayEnabled(day){
			
		   var date = new Date(day.date);
		   var dias=eval("#{frequenciaHome.turma.diasFuncionamentoNumeral}");
		   return (dias.indexOf(date.getDay())!=-1 &amp;&amp; date &lt;= (new Date()));
		}
		function getDisabledStyle(day){
		   if (!isDayEnabled(day)) return 'rich-calendar-boundary-dates disabledDay';
		}
		</script>

	</ui:define>

	<ui:define name="MenuInterno">
		<ui:include src="/layout/menu_turma.xhtml" />
	</ui:define>

	<ui:define name="body">

		<h2 class="t_turma">
			<h:outputText value="Frequência de Turma" />
		</h2>

		<div id="tamanho_div">

			<a:outputPanel id="pnlForm" ajaxRendered="true">
				<a:form id="formTurmaHome" styleClass="form_confea">
					<s:validateAll>

						<ol>

							<li><s:div>
									<p class="tool_alerta">Os campos marcados com * são de
										preenchimento obrigatório.</p>
								</s:div></li>
							<li>
								<fieldset>
									<legend>
										<h:outputText value="Dados da Turma" />
									</legend>
								</fieldset>
							</li>

					<li><s:decorate template="/layout/edit.xhtml" id="decoNome">
									<ui:define name="label">
							Turma
						</ui:define>
									<h:outputText value="#{frequenciaHome.turma.nome}" />

								</s:decorate></li>
								
						
						<li><s:decorate template="/layout/edit.xhtml"
									id="decoData">
									<ui:define name="label">
							Data
						</ui:define>
							
									<rich:calendar id="data" styleClass="campo_half data"
										value="#{frequenciaHome.data}"
										datePattern="dd/MM/yyyy" disabled="false" required="false"
										rendered="true"
										requiredMessage="O campo 'Data' é obrigatório."
										enableManualInput="true"
										style="position: static;margin-left: 150px;"
										immediate="true"
										isDayEnabled="isDayEnabled" 
										dayStyleClass="getDisabledStyle"
										firstWeekDay="1"
										locale="pt"
										>
										<f:validator validatorId="DataValidator" />
										<a4j:support event="onchanged" limitToList="true" reRender="div_frequencia"  
											action="#{frequenciaHome.listarAlunos}" ignoreDupResponses="true" eventsQueue="default" ajaxSingle="true"  />
									</rich:calendar>

								</s:decorate></li>
								
														
							<li>
								<fieldset>
									<legend>
										<h:outputText value="Frequências Voluntários" />
									</legend>
								</fieldset>
							</li>
							<s:div id="div_frequencia">
								<rich:dataTable value="#{frequenciaVoluntarios}" var="_frequencia"
											styleClass="grid_dados" cellpadding="0" cellspacing="0"
											border="0" id="frequenciaVoluntario" rowClasses="grid_zebra,none">
		
											<rich:column>
												<f:facet name="header">Nome</f:facet>
												<h:outputText value="#{_frequencia.voluntario.nome}" />
											</rich:column>
											
											<rich:column>
												<f:facet name="header">Presente</f:facet>
												
												<h:selectBooleanCheckbox value="#{_frequencia.presente}"  />
		
											</rich:column>
		
		
										</rich:dataTable>
								
								<li>
									<fieldset>
										<legend>
											<h:outputText value="Frequências Alunos" />
										</legend>
									</fieldset>
								</li>
							
								<rich:dataTable value="#{frequenciaAlunos}" var="_frequencia"
										styleClass="grid_dados" cellpadding="0" cellspacing="0"
										border="0" id="frequencia" rowClasses="grid_zebra,none">
	
										<rich:column>
											<f:facet name="header">Nome</f:facet>
											<h:outputText value="#{_frequencia.aluno.nome}" />
										</rich:column>
										
										<rich:column>
											<f:facet name="header">Presente</f:facet>
											
											<h:selectBooleanCheckbox value="#{_frequencia.presente}"  />
	
										</rich:column>
	
	
									</rich:dataTable>
							
							</s:div>
							

						</ol>

						<fieldset>
							<h:messages globalOnly="false" styleClass="tool_alerta" />
						</fieldset>

						<a4j:commandLink styleClass="btn" action="#{frequenciaHome.salvar}"
							value="Salvar" reRender="pnlForm" />

					</s:validateAll>
				</a:form>
			</a:outputPanel>
		</div>
	</ui:define>

</ui:composition>
